package com.example.cstr.controller;

import com.example.cstr.entity.ExchangeRules;
import com.example.cstr.entity.Message;
import com.example.cstr.service.ExchangeRulesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/ExchangeRules")
@Api(tags = "学时转换规则")
public class ExchangeRulesController {
    @Resource
    private ExchangeRulesService exchangeRulesService;

    @ApiOperation(value = "添加学时转换规则")
    @PostMapping("/add")
    public Message insertExchangeRules(ExchangeRules exchangeRules){
        return exchangeRulesService.insertSelective(exchangeRules)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "删除学时转换规则")
    @DeleteMapping("/delete")
    public Message deleteExchangeRules(Integer erId){
        return exchangeRulesService.deleteByPrimaryKey(erId)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "修改学时转换规则")
    @PutMapping("/update")
    public Message updateExchangeRules(ExchangeRules exchangeRules){
        return exchangeRulesService.updateByPrimaryKeySelective(exchangeRules)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "根据学时转换规则id查询学时转换规则信息")
    @GetMapping("/select")
    public Message selectExchangeRules(Integer erId){
        return exchangeRulesService.selectByPrimaryKey(erId)!=null?Message.success(null).add(exchangeRulesService.selectByPrimaryKey(erId)):Message.fail(null);
    }

    @ApiOperation(value = "查询所有学时转换规则信息")
    @GetMapping("/selectAll")
    public Message selectAllExchangeRules(){
        return Message.success(null).add(exchangeRulesService.selectAllExchangeRules());
    }

    @ApiOperation(value = "分页查询-查询所有文件信息")
    @GetMapping("/pagingSearch")
    public Message PagingSearch(@RequestParam Integer pageNum,@RequestParam Integer size){
        return exchangeRulesService.PagingSearch(pageNum,size);
    }

    @ApiOperation(value = "根据教育培训项目id查询学时转换规则信息")
    @GetMapping("/selectByEr_etp_id")
    public Message selectByEr_etp_id(Integer er_etp_id){
        return exchangeRulesService.selectByEr_etp_id(er_etp_id)!=null?Message.success(null).add(exchangeRulesService.selectByEr_etp_id(er_etp_id)):Message.fail(null);
    }
}
